#include<unistd.h> //getcwd , chdir头文件
#include<stdio.h>
#include<stdlib.h>//exit头文件

int main()
{
    char buf[1024]={0};//保存路径

    char* ret1 = getcwd(buf,sizeof(buf));//获取当前目录路径
    if(ret1 == NULL)
    {
        perror("getcwd");//获取失败
        exit(1);
    }
    else 
    {
        printf("当前路径：buf:%s\n",buf);
        printf("当前路径：ret1:%s\n",ret1);
    }

    int ret2 = chdir("../");//更换到上级目录
    if(ret2 == -1)
    {
        perror("chdir");
        exit(1);
    }
    else if(ret2 == 0)
    {
        getcwd(buf,sizeof(buf));
        printf("更换路径成功，当前路径：%s\n",buf);
    }
    return 0;
}
